package com.sky.controller.admin;

import com.sky.constant.RedisConstant;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 套餐管理
 */
@Api(tags = "套餐管理")
@RestController("AdminSetmealController")
@RequestMapping("/admin/setmeal")
public class SetmealController {

    private static final Logger log = LoggerFactory.getLogger(SetmealController.class);
    @Autowired
    private SetmealService setmealService;

    /**
     * 套餐分页查询
     * @return
     */
    @ApiOperation("套餐分页查询")
    @GetMapping("/page")
    public Result<Map<String,Object>> queryByPage(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("套餐分页查询:{}",setmealPageQueryDTO);
        return setmealService.queryByPage(setmealPageQueryDTO);
    }

    /**
     * 套餐新增
     * @param setmealVO
     * @return
     */
    @ApiOperation("套餐新增")
    @PostMapping
    @CacheEvict(value = RedisConstant.SHOP_CATEGORY_SETMEAL,allEntries = true)
    public Result saveSetmeal(@RequestBody SetmealVO setmealVO){
        log.info("套餐新增:{}",setmealVO);
        return setmealService.saveSetmeal(setmealVO);
    }

    /**
     * 套餐主键查询
     * @param id
     * @return
     */
    @ApiOperation("套餐主键查询")
    @GetMapping("/{id}")
    public Result<SetmealVO> queryById(@PathVariable Long id){
        log.info("套餐主键查询:{}",id);
        return setmealService.queryBySetmealWithSetmealDish(id);
    }

    /**
     * 套餐修改
     * @param setmealVO
     * @return
     */
    @ApiOperation("套餐修改")
    @PutMapping
    @CacheEvict(value = RedisConstant.SHOP_CATEGORY_SETMEAL,allEntries = true)
    public Result updateSetmeal(@RequestBody SetmealVO setmealVO){
        log.info("套餐修改:{}",setmealVO);
        return setmealService.updateSetmeal(setmealVO);
    }

    @ApiOperation("套餐启用或禁用")
    @PostMapping("/status/{status}")
    @CacheEvict(value = RedisConstant.SHOP_CATEGORY_SETMEAL,allEntries = true)
    public Result startOrStop(@PathVariable("status") Integer status,
                              @RequestParam("id") Integer id){
        log.info("套餐启用或禁用");
        return setmealService.startOrStop(status,id);
    }

    /**
     * 套餐批量删除
     * @param ids
     * @return
     */
    @ApiOperation("套餐批量删除")
    @DeleteMapping
    @CacheEvict(value = RedisConstant.SHOP_CATEGORY_SETMEAL,allEntries = true)
    public Result deleteSetmeal(@RequestParam List<Integer> ids){
        log.info("套餐批量删除:{}",ids);
        return setmealService.deleteSetmeal(ids);
    }

}
